package com.dingwen.stumybplu.exception;


import com.dingwen.stumybplu.result.Result;
import com.dingwen.stumybplu.result.ResultGenerator;

/**
* 服务异常
* @author dingwen
*/
public class ServiceException extends RuntimeException {
	private static final long serialVersionUID = 1L;

	private Result result;
	
	
	public Result result() {
		return result;
	}
	
	public ServiceException(Result r) {
		super(r.getMessage());
		this.result = r;
	}
	public ServiceException(Result r, Throwable cause) {
		super(r.getMessage(), cause);
		this.result = r;
	}

	public ServiceException(String... msg) {
		StringBuilder stringBuffer = new StringBuilder();
		if(msg != null) {
			for(String s : msg) {
				stringBuffer.append(s);
			}
		}
		String m = stringBuffer.toString();
		result = ResultGenerator.genFailureResult(m);
	}
	
	public ServiceException(Throwable cause) {
		super(cause);
	}
	public ServiceException(String message, Throwable cause) {
		super(message, cause);
		result = ResultGenerator.genFailureResult(message);
	}
	
	@Override
	public String getMessage() {
		return this.result.toString();
	}
	
}
